﻿using BW.WMS.Application.Features.Supperss.Dtos;
using BW.WMS.Application.Features.Supperss.Interfice;
using BW.WMS.Core.Result;
using BW.WMS.Domain.Entities.Supperrs;
using BW.WMS.Domain.Repositories;
using BW.WMS.Infrastructure.Data.Contexts;
using Dapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.WMS.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SuppersProductController : ControllerBase
    {

        private readonly ISupperServices supperServices;

        public SuppersProductController(ISupperServices supperServices)
        {
            this.supperServices = supperServices;
        }

        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public ApiResult<int> AddProduct(ProductModel product)
        {
            return supperServices.AddProduct(product);
        }
        /// <summary>
        /// 添加供应商
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public ApiResult<int> AddSupplier(SupplierModels supplier)
        {
            return supperServices.AddSupplier(supplier);
        }
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public ApiResult<int> DeleteProduct(int id)
        {
            return supperServices.DeleteProduct(id);

        }
        /// <summary>
        /// 删除供应商
        /// </summary>
        [HttpDelete]
        public ApiResult<int> DeleteSupplier(int id)
        {
            return supperServices.DeleteSupplier(id);
        }
        /// <summary>
        /// 根据供应商id获取商品列表
        /// </summary>
        /// 
        [HttpGet]
        public ApiResult<List<ProductModel>> GetProductsBySupplierId([FromQuery]int supplierId)
        {
            return supperServices.GetProductsBySupplierId(supplierId);
        }
        /// <summary>
        /// 获取供应商列表
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet]
        public ApiPage<SupplierModels> GetSupperProduct([FromQuery]SupperProductQueryDto queryDto)
        {

            return supperServices.GetSupperProduct(queryDto);


        }


        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 

        [HttpGet]
        public ApiPage<ProductModel> GetSupperProductPage([FromQuery]ProducstDto queryParams)
        {
             return supperServices.GetSupperProductPage(queryParams);
        }

        /// <summary>
        /// 根据供应商ID加载可采购商品列表
        /// </summary>
        [HttpGet]
        public ApiResult<List<SupplierProductInfoDto>> GetPurchaseProductsBySupplier([FromQuery]int supplierId)
        {
            return supperServices.GetPurchaseProductsBySupplier(supplierId);
        }

        /// <summary>
        /// 创建采购单
        /// </summary>
        [HttpPost]
        public ApiResult<int> CreatePurchaseOrder([FromBody]DbPurchaseList purchase)
        {
            return supperServices.CreatePurchaseOrder(purchase);
        }

        /// <summary>
        /// 分页查询采购单
        /// </summary>
        [HttpGet]
        public ApiPage<DbPurchaseList> GetPurchaseOrderPage([FromQuery]PurchaseOrderQueryDto query)
        {
            return supperServices.GetPurchaseOrderPage(query);
        }

        /// <summary>
        /// 查询进货列表
        /// </summary>
        [HttpGet]
        public ApiPage<PurchaseListDto> GetPurchaseList([FromQuery]PurchaseListQueryDto query)
        {
            return supperServices.GetPurchaseList(query);
        }

        /// <summary>
        /// 获取供应商下拉框数据
        /// </summary>
        [HttpGet]
        public ApiResult<List<SupplierDropdownDto>> GetSupplierDropdown()
        {
            return supperServices.GetSupplierDropdown();
        }
    }
}
